#encoding:utf8 

from aliyun.api import AlibabaAliqinFcSmsNumSendRequest
import ctypes, os, sys

class _LoginInfo(object):
    def __init__(self,appkey,secret):
        self.appkey = appkey
        self.secret = secret

class SmsSend:
    
    _info = None

    @classmethod
    def _chk_info(cls):
        if cls._info == None:

            sofile = os.path.join(os.path.split(__file__)[0], "lib{platform}parm.so".format(platform=sys.platform))
            lib = ctypes.CDLL(sofile)
            appkey = ctypes.string_at(lib.getAppkey(), -1)  
            secret = ctypes.string_at(lib.getSecret(), -1)

            cls._info = _LoginInfo(appkey = appkey,secret = secret)

    @classmethod
    def send_by_laoduan(cls, msgdict):
        cls._chk_info()

        req = AlibabaAliqinFcSmsNumSendRequest()
        req.set_app_info(cls._info)
        req.extend = ""
        req.sms_type = "normal"
        req.sms_free_sign_name = "老段"
        req.sms_param = msgdict["param"]
        req.rec_num = msgdict["phone"]
        req.sms_template_code = "SMS_25095074"

        try :
            resp = req.getResponse()
            print (resp)
        except Exception,e:
            print (e)





if __name__ == "__main__":
    msg = dict(
        phone = "18210403779",
        param = "{equip:'设备名称',server:'服务',statu:'状态'}",
    )

    SmsSend.send_by_laoduan(msg)

